/*
 * 展示公司信息交易
 * 参数   交易码：trancode=14110
 * 
 */

package org.ccams.tran;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ccams.domain.TCompany;
import org.ccams.util.PageParameter;
/**
 * 展示公司信息交易
 * @author liuguangshuai@gmail.com
 * @系统名称：定制化辅助生成制造系统
 * @时间：Aug 22, 2008
 */
public class Tran14110 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		int limit = Integer.parseInt(request.getParameter("limit"));
		int start = Integer.parseInt(request.getParameter("start"));
		PageParameter page = new PageParameter();
		page.setLimit(limit);
		page.setStart(start);
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		ArrayList<TCompany> al = new ArrayList<TCompany>();
		List<TCompany> list = getCcamsService().getTcompanyDao().getTCompanyByPage(page);
		int count = getCcamsService().getTcompanyDao().getTCompanyCount();
		for(TCompany t : list){
			TCompany u = new TCompany();
			u.setBengEndFin(t.getBengEndFin());
			u.setCompanyName(t.getCompanyName());
			u.setIdtCompany(t.getIdtCompany());
			u.setRegAddress(t.getRegAddress());
			u.setSmallName(t.getSmallName());
			u.setValid(t.getValid());
			al.add(u);
		}
		JSONArray JsonArray = JSONArray.fromObject(al); //得到JSON数组 
		jsonMap.put("totalProperty", count);
        jsonMap.put("root", JsonArray);
        json.putAll(jsonMap);
	}
}
